package cn.taokuaidi.wangwang.client.widget.toolbar;

import cn.taokuaidi.wangwang.client.context.SellerDataEventContext;
import cn.taokuaidi.wangwang.client.model.OrderDO;

import com.allen_sauer.gwt.log.client.Log;
import com.extjs.gxt.ui.client.data.BasePagingLoader;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.store.Store;
import com.extjs.gxt.ui.client.widget.StoreFilterField;

/**
 * @author 嘉陵江里捉鱼 email:tang7259@163.com
 *@version 1.0
 *@time Nov 4, 2008 10:17:10 AM
 */
public class SellerPagingToolBar extends TkdPagingToolBar {

    public SellerPagingToolBar(int pageSize) {
        super(pageSize);
        this.getMessages().setAfterPageText("{0}");
        this.getMessages().setBeforePageText("");
        this.getMessages().setDisplayMsg("{0}到{1} 共{2}条");
        this.getMessages().setEmptyMsg("无数据");
        this.getMessages().setFirstText("首页");
        this.getMessages().setLastText("未页");
        this.getMessages().setNextText("下页");
        this.getMessages().setPrevText("前页");
        this.getMessages().setRefreshText("刷新");
        BasePagingLoader loader = SellerDataEventContext.getLoader();
        ListStore<OrderDO> store = SellerDataEventContext.getStore();
        bind(loader);
        // 关联搜索组件
        StoreFilterField filter = new StoreFilterField<ModelData>() {

            @Override
            protected boolean doSelect(Store store, ModelData parent, ModelData record, String property, String filter) {
                Log.info("filter:" + filter);
                // 预先搜索buyer
                String buyer = record.get("buyer_nick");
                if (buyer != null) {
                    buyer = buyer.toLowerCase();
                    if (buyer.indexOf(filter.toLowerCase()) >= 0) {
                        return true;
                    }
                }
                // 然后匹配title
                String name = record.get("title");
                name = name.toLowerCase();
                if (name.indexOf(filter.toLowerCase()) >= 0) {
                    return true;
                }

                return false;
            }

        };
        filter.setToolTip("买家与商品名称模糊搜索");
        filter.bind(store);

        // this.getItems().add(0, new AdapterToolItem(filter));
        // this.getItems().add(1, new SeparatorToolItem());

    }
}
